public class cewsd {
    class Solution {
        public List<Integer> findAnagrams(String ss, String pp) {
            List<Integer> list = new ArrayList<>();
            char[] s = ss.toCharArray();
            char[] p = pp.toCharArray();//转换成字符数组
            int[] hash1 = new int[26];//存放p子串
            for(char ch:p){
                hash1[ch-'a']++;
            }
            int[] hash2 = new int[26];//窗口
            int m= p.length;
            for(int left =0, right = 0,count = 0;right<s.length ; right++){
                char in = s[right];
                hash2[in-'a']++;//进入窗口
                if(hash2[in-'a']<=hash1[in-'a']){
                    count++;//统计窗口有效个数
                }
                if(right-left+1>m){   //出窗口判断
                    char out = s[left++];
                    if(hash2[out-'a']-- <= hash1[out-'a']){

                        count--;
                    }
                }
                if(count==m){
                    list.add(left);//更新结果
                }
            }
            return list;
        }
    }
}
